package com.whfc.ms.api.md.controller;

import com.whfc.common.base.BaseController;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.emp.dto.AppBoardEmpAnalysisDTO;
import com.whfc.emp.dto.AppEmpBoardRecordAnalysisDTO;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.md.service.MdEmpBoardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author: hw
 * @date: 2021-11-17 11:40
 * @description: 数据大屏-人员大屏
 */
@RestController
@RequestMapping("/ms/api/md/board/emp")
public class MdEmpBoardController extends BaseController {


    @Autowired
    private MdEmpBoardService mdEmpBoardService;

    @GetMapping("/analysis")
    public Result empAnalysis(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                              @RequestParam("deptId") Integer deptId,
                              @RequestParam("startDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
                              @RequestParam("endDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {
        logger.info("大屏-人员分析，loginer:{},deptId:{},startDate:{},endDate：{}", user.getUsername(), deptId, startDate, endDate);
        AppBoardEmpAnalysisDTO data = mdEmpBoardService.empAnalysis(deptId, startDate, endDate);
        return ResultUtil.success(data);
    }


    @GetMapping("/record/analysis")
    public Result empRecordAnalysis(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                                    @RequestParam("deptId") Integer deptId,
                                    @RequestParam("startDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
                                    @RequestParam("endDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {
        logger.info("board人行记录，loginer:{},deptId:{},startDate:{},endDate：{}", user.getUsername(), deptId, startDate, endDate);
        AppEmpBoardRecordAnalysisDTO data = mdEmpBoardService.empRecordAnalysis(deptId, startDate, endDate);
        return ResultUtil.success(data);
    }

    @GetMapping("/record/analysis2")
    public Result empRecordAnalysis2(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                                     @RequestParam("deptId") Integer deptId,
                                     @RequestParam("startDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
                                     @RequestParam("endDate") @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {
        logger.info("board人行记录，loginer:{},deptId:{},startDate:{},endDate：{}", user.getUsername(), deptId, startDate, endDate);
        AppEmpBoardRecordAnalysisDTO data = mdEmpBoardService.empRecordAnalysis2(deptId, startDate, endDate);
        return ResultUtil.success(data);
    }

}
